home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-19 / gpt32src.zip / NEXT.TRM < prev    next >
Text File  |  1992-03-25  |  12KB  |  415 lines

  1. /*
  2.  * $Id$
  3.  *
  4.  * $Log$
  5.  */
  6.  
  7. /* GNUPLOT - next.trm */
  8. /*
  9.  * Copyright (C) 1991, 1992   
  10.  *
  11.  * Permission to use, copy, and distribute this software and its
  12.  * documentation for any purpose with or without fee is hereby granted, 
  13.  * provided that the above copyright notice appear in all copies and 
  14.  * that both that copyright notice and this permission notice appear 
  15.  * in supporting documentation.
  16.  *
  17.  * Permission to modify the software is granted, but not the right to
  18.  * distribute the modified code.  Modifications are to be distributed 
  19.  * as patches to released version.
  20.  *  
  21.  * This software  is provided "as is" without express or implied warranty.
  22.  * 
  23.  * This file is included by ../term.c.
  24.  *
  25.  * This terminal driver supports:
  26.  *     next
  27.  *
  28.  * AUTHORS
  29.  *  Nick Strobel from Russell Lang's post.trm
  30.  * 
  31.  * send your comments or suggestions to (info-gnuplot@ames.arc.nasa.gov).
  32.  *
  33.  * The 'postscript' driver produces landscape output 10" wide and 7" high.  
  34.  * To get a smaller epsf output use 'set size 0.5,0.5', 
  35.  * 'set term postscript portrait', make only one plot per file
  36.  * and change the first line of the postscript file from
  37.  * '%!PS-Adobe-2.0' to '%!PS-Adobe-2.0 EPSF-2.0'
  38.  * To change font to Times-Roman and font size to 20pts use 
  39.  * 'set term postscript "Times-Roman" 20'.
  40.  */
  41.  
  42.  
  43. /* NeXT driver by Nick Strobel, strobel@phast.phys.washington.edu */
  44. #import <math.h>
  45. #import <dpsclient/dpsclient.h>
  46. #import <dpsclient/dpsNeXT.h>
  47. #import <stdlib.h>
  48. #import "../EpsViewer.h"
  49.  
  50. DPSContext d;
  51. static void window_create(float width, float height);
  52. float width,height;    
  53. float xsize_orig,ysize_orig;  
  54.  
  55. char next_font[MAX_ID_LEN+1] = "Courier" ; /* name of font */
  56. int next_fontsize = 14;                     /* size of font in pts */
  57. BOOLEAN next_portrait = FALSE;                 /* vertical page */
  58. BOOLEAN next_color = FALSE;
  59. BOOLEAN init_called = FALSE;
  60. BOOLEAN initframe_called = FALSE;
  61.  
  62. int next_page=0;            /* page count */
  63. int next_path_count=0;     /* count of lines in path */
  64. int next_ang=0;            /* text angle */
  65. enum JUSTIFY next_justify=LEFT;    /* text is flush left */
  66.  
  67. char *NEXT_header[] = {
  68. "/vpt2 vpt 2 mul def\n",
  69. "/hpt2 hpt 2 mul def\n",
  70. /* flush left show */
  71. "/Lshow { currentpoint stroke moveto\n",
  72. "  0 vshift rmoveto show } def\n", 
  73. /* flush right show */
  74. "/Rshow { currentpoint stroke moveto\n",
  75. "  dup stringwidth pop neg vshift rmoveto show } def\n", 
  76. /* centred show */
  77. "/Cshow { currentpoint stroke moveto\n",
  78. "  dup stringwidth pop -2 div vshift rmoveto show } def\n", 
  79. /* Dash or Color Line */
  80. "/DL { Color {setrgbcolor [] 0 setdash pop}\n",
  81. " {pop pop pop 0 setdash} ifelse } def\n",
  82. /* Border Lines */
  83. "/BL { stroke gnulinewidth 2 mul setlinewidth } def\n",
  84. /* Axes Lines */
  85. "/AL { stroke gnulinewidth 2 div setlinewidth } def\n",
  86. /* Plot Lines */
  87. "/PL { stroke gnulinewidth setlinewidth } def\n",
  88. /* Line Types */
  89. "/LTb { BL [] 0 0 0 DL } def\n", /* border */
  90. "/LTa { AL [1 dl 2 dl] 0 setdash 0 0 0 setrgbcolor } def\n", /* axes */
  91. "/LT0 { PL [] 0 1 0 DL } def\n",
  92. "/LT1 { PL [4 dl 2 dl] 0 0 1 DL } def\n",
  93. "/LT2 { PL [2 dl 3 dl] 1 0 0 DL } def\n",
  94. "/LT3 { PL [1 dl 1.5 dl] 1 0 1 DL } def\n",
  95. "/LT4 { PL [5 dl 2 dl 1 dl 2 dl] 0 1 1 DL } def\n",
  96. "/LT5 { PL [4 dl 3 dl 1 dl 3 dl] 1 1 0 DL } def\n",
  97. "/LT6 { PL [2 dl 2 dl 2 dl 4 dl] 0 0 0 DL } def\n",
  98. "/LT7 { PL [2 dl 2 dl 2 dl 2 dl 2 dl 4 dl] 1 0.3 0 DL } def\n",
  99. "/LT8 { PL [2 dl 2 dl 2 dl 2 dl 2 dl 2 dl 2 dl 4 dl] 0.5 0.5 0.5 DL } def\n",
  100. "/M {moveto} def\n",
  101. "/L {lineto} def\n",
  102. "/P { stroke [] 0 setdash\n", /* Point */
  103. "  currentlinewidth 2 div sub moveto\n",
  104. "  0 currentlinewidth rlineto  stroke } def\n",
  105. "/D { stroke [] 0 setdash  2 copy  vpt add moveto\n", /* Diamond */
  106. "  hpt neg vpt neg rlineto  hpt vpt neg rlineto\n",
  107. "  hpt vpt rlineto  hpt neg vpt rlineto  closepath  stroke\n",
  108. "  P  } def\n",
  109. "/A { stroke [] 0 setdash  vpt sub moveto  0 vpt2 rlineto\n", /* Plus (Add) */
  110. "  currentpoint stroke moveto\n",
  111. "  hpt neg vpt neg rmoveto  hpt2 0 rlineto stroke\n",
  112. "  } def\n",
  113. "/B { stroke [] 0 setdash  2 copy  exch hpt sub exch vpt add moveto\n", /* Box */
  114. "  0 vpt2 neg rlineto  hpt2 0 rlineto  0 vpt2 rlineto\n",
  115. "  hpt2 neg 0 rlineto  closepath  stroke\n",
  116. "  P  } def\n",
  117. "/C { stroke [] 0 setdash  exch hpt sub exch vpt add moveto\n", /* Cross */
  118. "  hpt2 vpt2 neg rlineto  currentpoint  stroke  moveto\n",
  119. "  hpt2 neg 0 rmoveto  hpt2 vpt2 rlineto stroke  } def\n",
  120. "/T { stroke [] 0 setdash  2 copy  vpt 1.12 mul add moveto\n", /* Triangle */
  121. "  hpt neg vpt -1.62 mul rlineto\n",
  122. "  hpt 2 mul 0 rlineto\n",
  123. "  hpt neg vpt 1.62 mul rlineto  closepath  stroke\n",
  124. "  P  } def\n",
  125. "/S { 2 copy A C} def\n", /* Star */
  126. NULL
  127. };
  128.  
  129. #define NEXT_XOFF    50    /* page offset in pts */
  130. #define NEXT_YOFF    50
  131.  
  132. #define NEXT_XMAX 7200
  133. #define NEXT_YMAX 5040
  134.  
  135. #define NEXT_XLAST (NEXT_XMAX - 1)
  136. #define NEXT_YLAST (NEXT_YMAX - 1)
  137.  
  138. #define NEXT_VTIC (NEXT_YMAX/80)
  139. #define NEXT_HTIC (NEXT_YMAX/80)
  140.  
  141. #define NEXT_SC (10)                /* scale is 1pt = 10 units */
  142. #define    NEXT_LW (0.5*NEXT_SC)        /* linewidth = 0.5 pts */
  143.  
  144. #define NEXT_VCHAR (14*NEXT_SC)        /* default is 14 point characters */
  145. #define NEXT_HCHAR (14*NEXT_SC*6/10)
  146.  
  147. NEXT_options()
  148. {
  149.     extern struct value *const_express();
  150.     extern double real();
  151.  
  152.     if (!END_OF_COMMAND) {
  153.         if (almost_equals(c_token,"p$ortrait")) {
  154.             next_portrait=TRUE;
  155.             c_token++;
  156.         }
  157.         else if (almost_equals(c_token,"l$andscape")) {
  158.             next_portrait=FALSE;
  159.             c_token++;
  160.         }
  161.         else if (almost_equals(c_token,"d$efault")) {
  162.             next_portrait=FALSE;
  163.             next_color=FALSE;
  164.             strcpy(next_font,"Courier");
  165.             next_fontsize = 14;
  166.             c_token++;
  167.         }
  168.     }
  169.  
  170.     if (!END_OF_COMMAND) {
  171.         if (almost_equals(c_token,"m$onochrome")) {
  172.             next_color=FALSE;
  173.             c_token++;
  174.         }
  175.         else if (almost_equals(c_token,"c$olor")) {
  176.             next_color=TRUE;
  177.             c_token++;
  178.         }
  179.     }
  180.  
  181.     if (!END_OF_COMMAND && isstring(c_token)) {
  182.         quote_str(next_font,c_token);
  183.         c_token++;
  184.     }
  185.  
  186.     if (!END_OF_COMMAND) {
  187.         /* We have font size specified */
  188.         struct value a;
  189.         next_fontsize = (int)real(const_express(&a));
  190.         c_token++;
  191.         term_tbl[term].v_char = (unsigned int)(next_fontsize*NEXT_SC);
  192.         term_tbl[term].h_char = (unsigned int)(next_fontsize*NEXT_SC*6/10);
  193.     }
  194.  
  195.     sprintf(term_options,"%s %s \"%s\" %d",
  196.         next_portrait ? "portrait" : "landscape",
  197.         next_color ? "color" : "monochrome",next_font,next_fontsize);
  198. }
  199.  
  200.  
  201. NEXT_init()
  202. {
  203. struct termentry *t = &term_tbl[term];
  204. int i;
  205. float llx,lly,urx,ury;
  206. /* I commented out the postscript comment fields because they are not really 
  207. *  needed (even the bounding box). However, if you'd like to send all the
  208. *  postscript to the context d, they're still there for you
  209. */
  210.  
  211.         llx=NEXT_XOFF;
  212.         lly=NEXT_YOFF;
  213.  
  214.     if(!initframe_called) {
  215.         if(!next_portrait){
  216.             urx=(xsize*(NEXT_XMAX)/NEXT_SC+0.5+NEXT_XOFF);
  217.             ury=(ysize*(NEXT_YMAX)/NEXT_SC+0.5+NEXT_YOFF);
  218.         } else {
  219.             urx=(ysize*(NEXT_YMAX)/NEXT_SC+0.5+NEXT_XOFF);
  220.             ury=(xsize*(NEXT_XMAX)/NEXT_SC+0.5+NEXT_YOFF);
  221.         }
  222.           width=urx-llx;    
  223.           height=ury-lly;
  224.           xsize_orig=xsize;
  225.           ysize_orig=ysize;    
  226.           window_create(width,height);
  227.              d=DPSGetCurrentContext();
  228.        DPSPrintf(d,"/showpage {initgraphics} bind def\n");
  229.       }
  230.         DPSPrintf(d,"1 setgray\n");
  231.         DPSPrintf(d,"0 1 %g %g rectfill\n",rint(width),rint(height));
  232.         DPSPrintf(d,"0 setgray\n");
  233.         DPSPrintf(d,"0 1 %g %g rectstroke\n",rint(width),rint(height));
  234. //           DPSPrintf(d,"/_the_saved_vm_ save def\n");
  235.         DPSPrintf(d,"%g %g translate\n",-llx,-lly); /* KEEP this IN! */
  236.  
  237. //        DPSPrintf(d,"%%!PS-ADOBE-2.0 EPSF-2.0\n");
  238. //        DPSPrintf(d,"%%%%Creator: gnuplot\n");
  239. //        DPSPrintf(d,"%%%%DocumentFonts: %s\n", next_font);
  240. //        DPSPrintf(d,"%%%%BoundingBox: %d %d ", NEXT_XOFF,NEXT_YOFF);
  241. //        if (!next_portrait)
  242. //            DPSPrintf(d,"%d %d\n",(int)width, (int)height);
  243. //        else 
  244. //            DPSPrintf(d,"%d %d\n",(int)width, (int)height);
  245. //        DPSPrintf(d,"%%%%Pages: (atend)\n");
  246. //        DPSPrintf(d,"%%%%EndComments\n");
  247.         DPSPrintf(d,"/gnudict 40 dict def\ngnudict begin\n");
  248.         DPSPrintf(d,"/Color %s def\n",next_color ? "true" : "false");
  249.         DPSPrintf(d,"/gnulinewidth %.3f def\n",NEXT_LW);
  250.         DPSPrintf(d,"/vshift %d def\n", (int)(t->v_char)/(-3));
  251.         DPSPrintf(d,"/dl {%d mul} def\n",NEXT_SC); /* dash length */
  252.         DPSPrintf(d,"/hpt %.1f def\n",NEXT_HTIC/2.0);
  253.         DPSPrintf(d,"/vpt %.1f def\n",NEXT_VTIC/2.0);
  254.         for ( i=0; NEXT_header[i] != NULL; i++)
  255.             DPSPrintf(d,"%s",NEXT_header[i]);
  256.         DPSPrintf(d,"end\n");
  257. //        DPSPrintf(d,"%%%%EndProlog\n");
  258.         init_called=TRUE;
  259. }
  260.  
  261. static void window_create(float width, float height)
  262. {
  263.     initframe_called=TRUE;
  264.     
  265.     NXApp=[EpsViewer new];
  266.     [NXApp windowCreate:width Height:height];
  267. }
  268.  
  269. NEXT_graphics()
  270. {
  271. struct termentry *t = &term_tbl[term];
  272.     next_page++;
  273.     if(!init_called)
  274.         NEXT_init();    /* set up the frame properly */
  275.     init_called=FALSE;
  276. //    DPSPrintf(d,"%%%%Page: %d %d\n",next_page,next_page);
  277.     DPSPrintf(d,"gnudict begin\n");
  278.     DPSPrintf(d,"gsave\n");
  279.     DPSPrintf(d,"%d %d translate\n",NEXT_XOFF,NEXT_YOFF);
  280.     if (!next_portrait) {
  281. /* keep plot entirely in the window */
  282.         if(xsize>xsize_orig)
  283.             xsize=xsize_orig;
  284.         if(ysize>ysize_orig)
  285.             ysize=ysize_orig;
  286.         DPSPrintf(d,"%.3f %.3f scale\n", xsize/NEXT_SC, ysize/NEXT_SC);
  287.     }
  288.     else {
  289.         if(xsize>xsize_orig)
  290.             xsize=xsize_orig;
  291.         if(ysize>ysize_orig)
  292.             ysize=ysize_orig;
  293.         DPSPrintf(d,"%.3f %.3f scale\n", ysize/NEXT_SC, xsize/NEXT_SC);
  294.         DPSPrintf(d,"90 rotate\n0 %d translate\n", -NEXT_YMAX);
  295.     }
  296.     DPSPrintf(d,"0 setgray\n");
  297.     DPSPrintf(d,"/%s findfont %d ", next_font, (t->v_char) );
  298.     DPSPrintf(d,"scalefont setfont\n");
  299.     DPSPrintf(d,"newpath\n");
  300.     next_path_count = 0;    
  301. }
  302.  
  303.  
  304. NEXT_text()
  305. {
  306.     next_path_count = 0;
  307.     DPSPrintf(d,"stroke\ngrestore\nend\nshowpage\n");
  308. //    DPSPrintf(d,"\ngrestoreall _the_saved_vm_ restore\n");
  309.         
  310.     DPSFlushContext(d);
  311.     
  312.     
  313. }
  314.  
  315.  
  316. NEXT_reset()
  317. {    
  318.     DPSPrintf(d,"currentwindow termwindow\n");
  319.     DPSPrintf(d,"nulldevice\n");
  320.  
  321.     DPSFlushContext(d);
  322.     initframe_called=FALSE;
  323. }
  324.  
  325.  
  326. NEXT_linetype(linetype)
  327. int linetype;
  328. {
  329. char *line = "ba012345678"; 
  330.     DPSPrintf(d,"LT%c\n", line[(linetype%9)+2]);
  331.     next_path_count = 0;
  332. }
  333.  
  334.  
  335. NEXT_move(x,y)
  336. unsigned int x,y;
  337. {
  338.     DPSPrintf(d,"%d %d M\n", x, y);
  339.     next_path_count += 1;
  340. }
  341.  
  342.  
  343. NEXT_vector(x,y)
  344. unsigned int x,y;
  345. {
  346.     DPSPrintf(d,"%d %d L\n", x, y);
  347.     next_path_count += 1;
  348.     if (next_path_count >= 400) {
  349.         DPSPrintf(d,"currentpoint stroke moveto\n");
  350.         next_path_count = 0;
  351.     }
  352. }
  353.  
  354.  
  355. NEXT_put_text(x,y,str)
  356. unsigned int x, y;
  357. char *str;
  358. {
  359. char ch;
  360.     NEXT_move(x,y);
  361.     if (next_ang != 0)
  362.         DPSPrintf(d,"currentpoint gsave translate %d rotate 0 0 moveto\n"
  363.             ,next_ang*90);
  364. /*    NXPutc(psStream,'(');            */
  365.     DPSPrintf(d,"%c",'(');
  366.     ch = *str++;
  367.     while(ch!='\0') {
  368.         if ( (ch=='(') || (ch==')') || (ch=='\\') )
  369. /*            NXPutc(psStream,'\\');
  370.         NXPutc(psStream,ch);            */
  371.             DPSPrintf(d,"%c",'\\');
  372.         DPSPrintf(d,"%c",ch);
  373.         ch = *str++;
  374.     }
  375.     switch(next_justify) {
  376.         case LEFT : DPSPrintf(d,") Lshow\n");
  377.             break;
  378.         case CENTRE : DPSPrintf(d,") Cshow\n");
  379.             break;
  380.         case RIGHT : DPSPrintf(d,") Rshow\n");
  381.             break;
  382.     }
  383.     if (next_ang != 0)
  384.         DPSPrintf(d,"grestore\n");
  385.     next_path_count = 0;
  386. }
  387.  
  388. int NEXT_text_angle(ang)
  389. int ang;
  390. {
  391.     next_ang=ang;
  392.     return TRUE;
  393. }
  394.  
  395. int NEXT_justify_text(mode)
  396. enum JUSTIFY mode;
  397. {
  398.     next_justify=mode;
  399.     return TRUE;
  400. }
  401.  
  402. /* postscript point routines */
  403. NEXT_point(x,y,number)
  404. int x,y;
  405. int number;
  406. {
  407. char *point = "PDABCTS";
  408.     number %= POINT_TYPES;
  409.      if (number < -1)
  410.         number = -1;        /* negative types are all 'dot' */
  411.     DPSPrintf(d,"%d %d %c\n", x, y, point[number+1]);
  412.     next_path_count = 0;
  413. }
  414.  
  415.